<?php
include_once 'common_functions.php';
include_once 'common_classes.php';
session_start();

if(IsSet($_GET["logout"])) {
	unset($_SESSION['candidate']);
	unset($_SESSION['election']);
	unset($_SESSION['candidate_id']);
	header('location: candidate_login.php');
}elseif(IsSet($_POST)) {
	$username = $_POST['name'];
	$password = $_POST['password'];

	$election = QueryBuilder::loginCandidate($username, $password);

	// wrong login
	if($election[0] != -1) {
		
		$_SESSION['candidate'] = $username;
		$_SESSION['election'] = $election[0];
		$_SESSION['candidate_id'] = $election[1];
		
		//echo 'logged in ' . $username;
	}

	header('location: candidate_login.php');
}
?>